<!DOCTYPE HTML>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>填写订单号</title>
    <link rel="stylesheet" type="text/css" href="../css/aui.css" />

</head>

<body>
    <header class="aui-bar aui-bar-nav aui-bar-light" id="header">
        <a class="aui-pull-left aui-btn" tapmode onclick="api.closeWin();">
            <span class="aui-iconfont aui-icon-left" style="color:#ff4285"></span>
        </a>
        <div class="aui-title" style="color:#ff4285">填写订单号</div>

    </header>
    <footer class="aui-bar aui-bar-tab" id="footer" style="background:#ff4285;color:#fff;line-height:55px;" onclick="fnFullInOrderNumberNow();">
        <div>点击填写订单号
            <div>
    </footer>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="./conf/config.js"></script>
<script type="text/javascript" src="./js/common.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript">
    apiready = function() {
        var header = $api.byId('header'); //获取节点
        var footer = $api.byId('footer'); //获取节点
        $api.fixStatusBar($api.dom('header'));
        api.setStatusBarStyle({
            style: 'dark',
           color:'transparent'
        });
        var headerH = $api.offset(header).h; //获取header的高
        var footerH = $api.offset(footer).h; //获取header的高
        api.openFrame({ //打开一个frame
            name: 'fill_in_order_number_frame',
            url: './fill_in_order_number_frame.html',
            rect: { //定位下面
                x: 0,
                y: headerH,
                w: 'auto',
                h: api.winHeight - footerH - headerH
            },
            pageParam: { //需要传到下个页面的参数
                orderId: api.pageParam.orderId
            },
            bounces: true, //弹跳开启
            allowEdit: true
        });
    };

    function fnFullInOrderNumberNow() {


        //   api.openFrame({
        //     name: 'fill_in_order_number_val_frame',
        //     url: './fill_in_order_number_val_frame.html',
        //     bgColor: 'rgba(0, 0, 0, 0.5)',
        //     rect: {
        //         x: 0,
        //         y: 0,
        //         w: 'auto',
        //         h: 'auto'
        //     },
        //     pageParam: {
        //         name: 'test'
        //     },
        //
        //     bounces: false
        // });
        var dialogBox = api.require('dialogBox');
        dialogBox.input({
            keyboardType: 'default',
            texts: {
                title: '填写订单号：',
                placeholder: '请输入订单号',
                leftBtnTitle: '取消',
                rightBtnTitle: '确定'
            },
            styles: {
                bg: '#fff',
                corner: 2,
                w: 300,
                h: 180,
                title: {
                    h: 40,
                    marginT: 20,
                    alignment: 'center',
                    size: 16,
                    color: '#000',

                },
                input: {
                    h: 60,
                    marginLeft: 10,
                    marginRight: 10,
                    textSize: 14,
                    textColor: '#000',
                    borderWidth: 1
                },
                dividingLine: {
                    width: 0.5,
                    color: '#696969'
                },
                left: {
                    bg: 'rgba(0,0,0,0)',
                    color: '#007FFF',
                    size: 12,
                    h: 40
                },
                right: {
                    bg: 'rgba(0,0,0,0)',
                    color: '#007FFF',
                    size: 12,
                    h: 40
                }
            }
        }, function(ret) {
            // var index = ret.buttonIndex;
            // var text = ret.text;
            // if (index == 1) {
            //     //alert(text);
            //     fnSubmitOrderNumber(text, orderId);
            // }
            // api.alert({
            //     msg: JSON.stringify(ret)
            // });
            if (ret.eventType == 'right') {
                fnSubmitOrderNumber(ret.text);

                //fnSubmitOrderNumber(ret.text, orderId);
                //  alert(ret.text);

            }
            var dialogBox = api.require('dialogBox');
            dialogBox.close({
                dialogName: 'input'
            });

        });
        return false;
//        api.prompt({
//            title: '输入订单号：',
//            buttons: ['确定', '取消']
//        }, function(ret, err) {
//            var index = ret.buttonIndex;
//            var text = ret.text;
//            if (index == 1) {
//                //alert(text);
//                fnSubmitOrderNumber(text);
//            }
//        });
    }

    function fnSubmitOrderNumber(text) {
        var userInfo = $api.getStorage("userInfo");
        //alert(JSON.stringify(userInfo));
        var userid = userInfo.userid;
        var random = userInfo.random;
        var order_id = api.pageParam.orderId;

        api.ajax({
            url: SITE_URL + 'index.php?m=api&c=appnew&a=fill_order_sn',
            method: 'POST',
            data: {
                values: {
                    "userid": userid,
                    "random": random,
                    "order_id": order_id,
                    "order_sn": text,

                }
            }
        }, function(ret, err) {
            if (ret.status == 1) {
              api.toast({
                  msg: ret.msg,
                  duration: 2000,
                  location: 'middle'
              });
                //alert(ret.msg);
                closeWin();
                //在别别窗口中打开执行刷新
            } else {
                alert(ret.msg);
            }
        })
    }

    // function GoToRefresh() {
    //     api.execScript({
    //         name: 'task_ing',
    //         frameName: 'task_ing_frame_1',
    //         script: 'location.reload();'
    //     });
    // }

    function closeWin() {
        GoToRefresh(); //关闭窗口时先刷新指定窗口页面,如需刷新主界面，name请填写root
        api.closeWin({});
    }

    function GoToRefresh() {
        api.execScript({
            name: 'task_ing',
            frameName: 'task_ing_frame_1',
            script: 'fnGetDataCommon("MyHome","index.php?m=api&c=appnew&a=get_userinfo","get")'
        });
    }
</script>

</html>
